package com.sqx.modules.trendsComment.controller;

import com.sqx.common.utils.Result;
import com.sqx.modules.trendsComment.entity.TrendsComment;
import com.sqx.modules.trendsComment.service.ITrendsCommentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 动态评论-管理端
 *
 * @author wuChang
 * @since 2023-09-26
 */
@RestController
@Api(value = "动态评论-管理端", tags = {"动态评论-管理端"})
@RequestMapping("/admin/trendsComment/")
public class AdminTrendsCommentController {
    @Autowired
    private ITrendsCommentService iTrendsCommentService;

    /**
     * 获取评论列表
     *
     * @param page          第几页
     * @param limit         多少条
     * @param trendsComment
     * @return
     */
    @ApiOperation("获取评论列表")
    @GetMapping(value = "getCommentList")
    public Result getCommentList(@ApiParam("页码") Integer page,
                                 @ApiParam("条数")Integer limit,
                                 @ApiParam("动态评论实体")TrendsComment trendsComment) {
        return Result.success().put("data", iTrendsCommentService.getCommentList(page, limit, null, trendsComment));
    }

    /**
     * 新增动态评论
     *
     * @param trendsComment
     * @return
     */
    @ApiOperation("新增或修改动态评论")
    @PostMapping(value = "saveTrendsComment")
    public Result saveTrendsComment(@ApiParam("动态评论实体")TrendsComment trendsComment) {
        return iTrendsCommentService.saveTrendsComment(trendsComment);
    }

    /**
     * 删除评论
     *
     * @param commentId 评论id
     * @return
     */
    @ApiOperation("删除评论")
    @PostMapping(value = "deleteTrendsComment")
    public Result deleteTrendsComment(@ApiParam("评论id")Long commentId) {
        return iTrendsCommentService.removeById(commentId) ? Result.success() : Result.error();
    }

    @ApiOperation("管理端获取回复的评论列表")
    @GetMapping(value = "getReplyCommentList")
    public Result getReplyCommentList(@ApiParam("页数")Integer page,
                                      @ApiParam("条数")Integer limit,
                                      @ApiParam("动态评论实体")TrendsComment trendsComment) {
        return Result.success().put("data", iTrendsCommentService.getAdminCommentList(page, limit,trendsComment));
    }


}
